package com.parmal.proxy;

import com.parmal.proxy.configuration.HttpProxyConfiguration;
import com.parmal.proxy.server.HttpProxyForwardStarter;
import com.parmal.proxy.server.HttpProxyServerStarter;
import io.netty.bootstrap.Bootstrap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class ApplicationMain {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ApplicationMain.class, args);

        HttpProxyConfiguration configuration = context.getBean(HttpProxyConfiguration.class);

        HttpProxyForwardStarter forwardStarter = context.getBean(HttpProxyForwardStarter.class, configuration);
        Bootstrap clientBootstrap = forwardStarter.start();

        HttpProxyServerStarter serverStarter = context.getBean(HttpProxyServerStarter.class, configuration,
                clientBootstrap);

        serverStarter.start();
    }


}
